/**
 * 
 */
package com.jr.javachat.client;

import com.jr.javachat.listener.RemoteContentListener;
import java.io.*;
import java.net.*;
import java.util.Scanner;

/**
 * Client
 * 
 * 编写时间：2011-5-8下午10:11:10
 * @author <a href="http://xiulin.tk/">彭修林</a>
 * 
 */
public class Client {

	private Socket server;
	private OutputStream os;
	private DataOutputStream out;
	private InputStream is;
	private DataInputStream in;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Client().init();
	}

	/**
	 * 
	 */
	private void init() {
		try {
			server = new Socket("127.0.0.1",23);
			is = server.getInputStream();
			in = new DataInputStream(is);
			os = server.getOutputStream();
			out = new DataOutputStream(os);
			RemoteContentListener listener = new RemoteContentListener(in);
			Thread t = new Thread(listener);
			t.start();
			Scanner scan = new Scanner(System.in);
			while(true){
				String inputHere = scan.next();
				out.writeUTF(inputHere );
			}
		} catch (UnknownHostException e) {
			e.printStackTrace();
			System.err.println("未知的主机，连接错误");
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("远程主机无法访问");
		}
	}

}
